var StorageKey = {
    "BOOKMAP_MAPPINGS": "BOOKMAP_MAPPINGS3",
    "PREVIOUS_FOLDER": "PREVIOUS_FOLDER",
    "MUTEXT_RULES": "MUTEXT_RULES",
    "MUTEX_SAME_INDEX": "MUTEX_SAME_INDEX",
    "AUTO_CLOSE_POPUP": "AUTO_CLOSE_POPUP",
};
var StorageKeys = Object.values(StorageKey);
var DefaultBookmarkMappings = JSON.stringify([
]);
var DefaultMutextRules = JSON.stringify([
]);

let id2node = {};
let folder_path_separtor = " / ";

function recursiveBookmarkTreeNodes(nodes, parent, output) {
    // 重置
    if (!parent) {
        id2node = {};
    }
    if (!output) {
        output = [];
    }
    nodes.forEach(node => {
        id2node[node.id] = node;
        if (node.children) {
            // 书签文件夹
            if (node.id != 0) {
                output.push(node.id);
            }
            recursiveBookmarkTreeNodes(node.children, node, output);
        } else {
            // 书签
        }
    });
    return output;
}
function findBookmarkByUrl(nodes, url) {
    let ret = null;
    for (let node of nodes) {
        if (ret) break;
        if (node.children) {
            ret = findBookmarkByUrl(node.children, url);
        } else {
            // 书签
            if (node.url == url) {
                ret = node;
            }
        }
    }
    return ret;
}